<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="search_from">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="id" placeholder="请输入ID" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="order_no" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收货人姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="full_name" placeholder="请输入收货人姓名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tel" placeholder="请输入电话" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商家</label>
                            <div class="layui-input-inline">
                                <script type="text/html" template lay-url="{{ layui.setter.apiHost }}/seller/seller/select" lay-done="layui.form.render();">
                                    <select name="seller_id">
                                        <option value=""></option>
                                        {{# layui.each(d.data, function(index, item){ }}
                                        <option value="{{ index }}">{{ item }}</option>
                                        {{# }); }}
                                    </select>
                                </script>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <script type="text/html" template lay-url="{{ layui.setter.apiHost }}/order/order/get_status" lay-done="layui.form.render();">
                                    <select name="status">
                                        <option value=""></option>
                                        {{# layui.each(d.data, function(index, item){ }}
                                        <option value="{{ index }}">{{ item }}</option>
                                        {{# }); }}
                                    </select>
                                </script>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search_button">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>

                <script type="text/html" id="toolbar_tmp">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="delivery">批量发货(电子面单)</button>
                        <button class="layui-btn layui-btn-sm" lay-event="print_goods">批量打印发货单</button>
                        <button class="layui-btn layui-btn-sm" lay-event="print_delivery">批量打印快递单</button>
                    </div>
                </script>

                <div class="layui-card-body">
                    <table id="table_list" lay-filter="table_list"></table>
                    <script type="text/html" id="flag_tmp">
                        {{# if(d.flag == 1){ }}
                        <span class="layui-badge">风险</span>
                        {{# } else { }}
                        <span class="layui-badge layui-bg-green">正常</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="action_button">
                        <a class="layui-btn layui-btn-xs" lay-event="detail">订单详情</a>
                        {{# if(d.status != 0){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="print_goods">发货单</a>
                        <a class="layui-btn layui-btn-xs" lay-event="print_delivery">快递单</a>
                        {{# } }}
                        {{# if(d.status == 0){ }}
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="update_price">改价</a>
                        {{# } }}
                        {{# if(d.status == 0 || d.status == 1){ }}
                        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="update_address">修改地址</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'helper'], function () {
        var admin = layui.admin,
            table = layui.table,
            form = layui.form,
            helper = layui.helper,
            api_action_url = layui.setter.apiHost + '/order/order';

        //表格操作
        table.render({
            elem: '#table_list',
            url: api_action_url,
            toolbar: '#toolbar_tmp',
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', title: 'ID', width: 80},
                {field: 'order_no', title: '订单号', minWidth: 200},
                {field: 'full_name', title: '收货人', width: 80},
                {field: 'tel', title: '电话', width: 120},
                {field: 'payment', title: '支付方式', width: 100},
                {field: 'subtotal', title: '支付金额', minWidth: 100},
                {field: 'username', title: '用户名', width: 120},
                {field: 'pay_at', title: '支付时间', width: 170},
                {field: 'created_at', title: '下单时间', width: 170},
                {field: 'status_text', title: '状态', width: 100, fixed: 'right'},
                {field: 'flag', title: '风险单', width: 80, fixed: 'right', templet: '#flag_tmp'},
                {title: '操作', minWidth: 260, align: 'left', fixed: 'right', toolbar: '#action_button'}
            ]],
            page: true
        });

        //头部工具栏操作
        table.on('toolbar(table_list)', function (obj) {
            var type = obj.event;
            data_id = get_id();
            switch (type) {
                case 'delivery':
                    helper.open_window('批量发货', api_action_url, 'order/order/batch_delivery', {width: '100%'}, {id: data_id});
                    break;
                case 'print_goods':
                    helper.open_window('批量打印发货单', api_action_url, 'order/order/print_goods', {width: '100%'}, {id: data_id});
                    break;
                case 'print_delivery':
                    helper.open_window('批量发货', api_action_url, 'order/order/print_delivery', {width: '100%'}, {id: data_id});
                    break;
            }
        });

        //监听工具条操作按钮
        table.on('tool(table_list)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'detail':
                    helper.open_window('订单详情', api_action_url, 'order/order/detail', {width: '100%'}, {id: data.id});
                    break;
                case 'update_price':
                    var update_price_data = {
                        id: data.id,
                        width: '500px',
                        detail_url: api_action_url + '/get_price',//获取数据地址
                        save_url: api_action_url + '/update_price',//保存地址
                    };
                    helper.open_window('改价', api_action_url, 'order/order/update_price', update_price_data);
                    break;
                case 'update_address':
                    var update_address_data = {
                        id: data.id,
                        width: '500px',
                        detail_url: api_action_url + '/get_address',//获取数据地址
                        save_url: api_action_url + '/update_address',//保存地址
                    };
                    helper.open_window('修改地址', api_action_url, 'order/order/update_address', update_address_data);
                    break;
                case 'print_goods':
                    helper.open_window('打印发货单', api_action_url, 'order/order/print_goods', {width: '100%'}, {id: [data.id]});
                    break;
                case 'print_delivery':
                    helper.open_window('打印快递单', api_action_url, 'order/order/print_delivery', {width: '100%'}, {id: [data.id]});
                    break;
            }
        });

        function get_id() {
            var data_id = new Array();
            var checkStatus = table.checkStatus('table_list'),
                select_data = checkStatus.data;
            for (var i = 0; i < select_data.length; i++) {
                data_id.push(select_data[i].id);
            }
            return data_id;
        }
    });
</script>
</body>
</html>